<template>
    <div>
        <el-row :gutter="15">
			<el-form ref="elForm" :model="dataForm" :rules="rules" size="medium" label-width="150px" label-position="right" :disabled="setting.readonly">
				<el-col :span="12" v-if="JudgeShow('zyzmc')">
					<el-form-item label="作业证名称" prop="zyzmc" >
						<el-input v-model="dataForm.zyzmc"  :disabled ="JudgeWrite('zyzmc')"  placeholder="请输入" clearable :style='{"width":"100%"}' >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('zyzbh')">
					<el-form-item label="作业证编号" prop="zyzbh" >
						<el-input v-model="dataForm.zyzbh"  :disabled ="JudgeWrite('zyzbh')"  placeholder="系统自动生成" readonly >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('dzdd')">
					<el-form-item label="吊装地点" prop="dzdd" >
						<el-input v-model="dataForm.dzdd"  :disabled ="JudgeWrite('dzdd')"  placeholder="请输入" clearable :style='{"width":"100%"}' >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('dzgjmc')">
					<el-form-item label="吊装工具名称" prop="dzgjmc" >
						<el-input v-model="dataForm.dzgjmc"  :disabled ="JudgeWrite('dzgjmc')"  placeholder="请输入" clearable :style='{"width":"100%"}' >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('dzryzyzh')">
					<el-form-item label="吊装人员作业证号" prop="dzryzyzh" >
						<el-input v-model="dataForm.dzryzyzh"  :disabled ="JudgeWrite('dzryzyzh')"  placeholder="请输入" clearable :style='{"width":"100%"}' >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('dzzhzyzh')">
					<el-form-item label="吊装指挥作业证号" prop="dzzhzyzh" >
						<el-input v-model="dataForm.dzzhzyzh"  :disabled ="JudgeWrite('dzzhzyzh')"  placeholder="请输入" clearable :style='{"width":"100%"}' >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('jhr')">
					<el-form-item label="监护人" prop="jhr" >
						<el-select v-model="dataForm.jhr"  :disabled ="JudgeWrite('jhr')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in jhrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('qdzwzl')">
					<el-form-item label="起吊重物质量（t）" prop="qdzwzl" >
						<el-input v-model="dataForm.qdzwzl"  :disabled ="JudgeWrite('qdzwzl')"  placeholder="请输入" clearable :style='{"width":"100%"}' >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('dzzykssj')">
					<el-form-item label="吊装作业开始时间" prop="dzzykssj" >
						<el-date-picker v-model="dataForm.dzzykssj"  :disabled ="JudgeWrite('dzzykssj')"  placeholder="请选择" clearable :style='{"width":"100%"}' type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('dzzyjssj')">
					<el-form-item label="吊装作业结束时间" prop="dzzyjssj" >
						<el-date-picker v-model="dataForm.dzzyjssj"  :disabled ="JudgeWrite('dzzyjssj')"  placeholder="请选择" clearable :style='{"width":"100%"}' type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('sqrq')">
					<el-form-item label="申请日期" prop="sqrq" >
						<el-date-picker v-model="dataForm.sqrq"  :disabled ="JudgeWrite('sqrq')"  placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('dznr')">
					<el-form-item label="吊装内容" prop="dznr" >
						<el-input v-model="dataForm.dznr"  :disabled ="JudgeWrite('dznr')"  placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":100}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('whbs')">
					<el-form-item label="危害辨识" prop="whbs" >
						<el-input v-model="dataForm.whbs"  :disabled ="JudgeWrite('whbs')"  placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":100}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('aqcsqrr')">
					<el-form-item label="安全措施确认人" prop="aqcsqrr" >
						<el-select v-model="dataForm.aqcsqrr"  :disabled ="JudgeWrite('aqcsqrr')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in aqcsqrrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('qtaqcs')">
					<el-form-item label="其他安全措施" prop="qtaqcs" >
						<el-input v-model="dataForm.qtaqcs"  :disabled ="JudgeWrite('qtaqcs')"  placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":100}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('qtaqcsqrr')">
					<el-form-item label="其他安全措施确认人" prop="qtaqcsqrr" >
						<el-select v-model="dataForm.qtaqcsqrr"  :disabled ="JudgeWrite('qtaqcsqrr')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in qtaqcsqrrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('ssaqjyr')">
					<el-form-item label="实施安全教育人" prop="ssaqjyr" >
						<el-select v-model="dataForm.ssaqjyr"  :disabled ="JudgeWrite('ssaqjyr')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ssaqjyrOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('scdwaqbmfzrqz')">
					<el-form-item label="安全部门负责人签字" prop="scdwaqbmfzrqz" >
						<el-select v-model="dataForm.scdwaqbmfzrqz"  :disabled ="JudgeWrite('scdwaqbmfzrqz')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in scdwaqbmfzrqzOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('scdwfzrqz')">
					<el-form-item label="生产单位负责人签字" prop="scdwfzrqz" >
						<el-select v-model="dataForm.scdwfzrqz"  :disabled ="JudgeWrite('scdwfzrqz')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in scdwfzrqzOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('zydwaqbmfzrqz')">
					<el-form-item label="安全部门负责人签字" prop="zydwaqbmfzrqz" >
						<el-select v-model="dataForm.zydwaqbmfzrqz"  :disabled ="JudgeWrite('zydwaqbmfzrqz')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in zydwaqbmfzrqzOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('zydwfzrqz')">
					<el-form-item label="作业单位负责人签字" prop="zydwfzrqz" >
						<el-select v-model="dataForm.zydwfzrqz"  :disabled ="JudgeWrite('zydwfzrqz')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in zydwfzrqzOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="JudgeShow('spbmyj')">
					<el-form-item label="审批部门意见" prop="spbmyj" >
						<el-input v-model="dataForm.spbmyj"  :disabled ="JudgeWrite('spbmyj')"  placeholder="请输入" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":100}' >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('spbmqz')">
					<el-form-item label="审批部门签字" prop="spbmqz" >
						<el-select v-model="dataForm.spbmqz"  :disabled ="JudgeWrite('spbmqz')"  placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in spbmqzOptions" :key="index" :label="item.F_RealName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12" v-if="JudgeShow('spsj')">
					<el-form-item label="审批时间" prop="spsj" >
						<el-date-picker v-model="dataForm.spsj"  :disabled ="JudgeWrite('spsj')"  placeholder="请选择" clearable :style='{"width":"100%"}' type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
			</el-form>

        </el-row>
        <UserBox v-if="userBoxVisible" ref="userBox" @submit="submit" />
    </div>
</template>
<script>
    import request from '@/utils/request'
    import { previewDataInterface } from '@/api/systemData/dataInterface'
    import { getDictionaryDataSelector } from '@/api/systemData/dictionary'
    export default {
        components: {},
        props: [],
        data() {
            return {
                visible: false,
                setting: {},
                eventType: '',
                userBoxVisible: false,
                dataForm: {
                    id:'',                    
					flowId: '',
					actionType:1,
					freeApproverUserId: '',
					zyzmc:undefined,
					zyzbh:undefined,
					dzdd:undefined,
					dzgjmc:undefined,
					dzryzyzh:undefined,
					dzzhzyzh:undefined,
					jhr:undefined,
					qdzwzl:undefined,
					dzzykssj:undefined,
					dzzyjssj:undefined,
					sqrq:undefined,
					dznr:undefined,
					whbs:undefined,
					aqcsqrr:undefined,
					qtaqcs:undefined,
					qtaqcsqrr:undefined,
					ssaqjyr:undefined,
					scdwaqbmfzrqz:undefined,
					scdwfzrqz:undefined,
					zydwaqbmfzrqz:undefined,
					zydwfzrqz:undefined,
					spbmyj:undefined,
					spbmqz:undefined,
					spsj:undefined,

                },
                rules: {

                },
				jhrOptions:[],
				aqcsqrrOptions:[],
				qtaqcsqrrOptions:[],
				ssaqjyrOptions:[],
				scdwaqbmfzrqzOptions:[],
				scdwfzrqzOptions:[],
				zydwaqbmfzrqzOptions:[],
				zydwfzrqzOptions:[],
				spbmqzOptions:[],


            }
        },
        computed: {},
        watch: {},
        created() {
		this.getjhrOptions();
		this.getaqcsqrrOptions();
		this.getqtaqcsqrrOptions();
		this.getssaqjyrOptions();
		this.getscdwaqbmfzrqzOptions();
		this.getscdwfzrqzOptions();
		this.getzydwaqbmfzrqzOptions();
		this.getzydwfzrqzOptions();
		this.getspbmqzOptions();

        },
        mounted() { },
        methods: {
		getjhrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.jhrOptions = res.data
			})
		},
		getaqcsqrrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.aqcsqrrOptions = res.data
			})
		},
		getqtaqcsqrrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.qtaqcsqrrOptions = res.data
			})
		},
		getssaqjyrOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.ssaqjyrOptions = res.data
			})
		},
		getscdwaqbmfzrqzOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.scdwaqbmfzrqzOptions = res.data
			})
		},
		getscdwfzrqzOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.scdwfzrqzOptions = res.data
			})
		},
		getzydwaqbmfzrqzOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.zydwaqbmfzrqzOptions = res.data
			})
		},
		getzydwfzrqzOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.zydwfzrqzOptions = res.data
			})
		},
		getspbmqzOptions()
		{
			previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
				this.spbmqzOptions = res.data
			})
		},

            goBack() {
                this.$emit('refresh')
            },
            init(data) {

                this.loading = true
                this.dataForm.id = data.id || ''
                this.setting = data
                this.visible = true;
                this.$nextTick(() => {
                    this.$refs['elForm'].resetFields();
                    if (this.dataForm.id) {
                        request({
                            url: '/api/WorkFlowForm/qyaqscDzaqzyz/' + this.dataForm.id,
                            method: 'get'
                        }).then(res => {
                            this.dataForm = res.data

                        })
                    } else {
                        this.dataForm.flowId = data.flowId
                    }
                    this.loading = false
                })
            },
            // 表单提交
            dataFormSubmit(eventType) {            

                this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                        if (eventType === 'audit' || eventType === 'reject') {
                            this.$emit('approval', this.dataForm, eventType)
                            return
                         }
                        this.dataForm.actionType = eventType === 'submit' ? 0 : 1
                        this.eventType = eventType
                        if (this.eventType === 'submit') {
                            if (this.setting.freeApprover == 0) {
                                this.$confirm('您确定要提交当前流程吗, 是否继续?', '提示', {
                                    type: 'warning'
                                }).then(() => {
                                    this.submit()
                                }).catch(() => { });
                            } else {
                                this.userBoxVisible = true
                                this.$nextTick(() => {
                                    this.$refs.userBox.init()
                                })
                            }
                        } else {
                            this.request()
                        }
                    }
                })
            },
            submit(freeApproverUserId) {
                if (freeApproverUserId) this.dataForm.freeApproverUserId = freeApproverUserId
                this.request()
            },
            request() {
                if (!this.dataForm.id) {
                    delete (this.dataForm.id)
                    request({
                        url: '/api/WorkFlowForm/qyaqscDzaqzyz',
                        method: 'post',
                        data: this.dataForm
                    }).then((res) => {
                        this.$message({
                            message: res.msg,
                            type: 'success',
                            duration: 1000,
                            onClose: () => {
                                this.visible = false
                                this.$emit('close', true)
                            }
                        })
                    })
                } else {
                    request({
                        url: '/api/WorkFlowForm/qyaqscDzaqzyz/' + this.dataForm.id,
                        method: 'PUT',
                        data: this.dataForm
                    }).then((res) => {
                        this.$message({
                            message: res.msg,
                            type: 'success',
                            duration: 1000,
                            onClose: () => {
                                this.visible = false
                                this.$emit('close', true)
                            }
                        })
                    })
                }
            },
            JudgeShow(id) {
                if (!this.setting.formOperates || !this.setting.formOperates.length) return true
                let arr = this.setting.formOperates.filter(o => o.id === id) || []
                if (!arr.length) return true
                let item = arr[0]
                return item.read
            },
            JudgeWrite(id) {
                if (!this.setting.formOperates || !this.setting.formOperates.length) return false
                let arr = this.setting.formOperates.filter(o => o.id === id) || []
                if (!arr.length) return true
                let item = arr[0]
                return !item.write
            },

        },
    }

</script>
